<?php
class persons extends CI_Controller{
	public function index()
	{
		//Get all persons - /persons  [GET]
		echo "flkdfsjklfk";
		$this->load->library('user');
		$users = $this->user->GetAll();
		
	}
	
	public function person($mail = "", $action = "")
	{
		$postData = $this->decoder->Decode();
		/*
		echo file_get_contents('php://input');
		$a = json_decode(file_get_contents('php://input'));
		var_dump($a);
		*/
		
		//Get Person - /persons/person/$mail  [GET]
		if ($action == "" && $mail != "" && $_SERVER['REQUEST_METHOD'] == "GET")
		{
		
		}
		
		//Delete Person - /persons/person/$mail/delete  [GET]
		if ( strtolower($action) == "delete" && $_SERVER['REQUEST_METHOD'] == "GET")
		{
			if ($mail != "")
			{
				$this->load->library('user');
				$this->user->DeleteByEmail($mail);
			}
		}
		
		//Add Person - /persons/person  [POST]
		if ($action == "" && $_SERVER['REQUEST_METHOD'] == "POST")
		{
		
			$person = $postData->person;
			var_dump($person);
			
			$this->load->model('user_m');
			$this->user_m->username = $person->user->username;
			$this->user_m->email = $person->user->email;
			$this->user_m->password = $person->user->password;
			$this->user_m->phone = $person->user->phone;
			
			$this->load->model('person_m');
			$this->person_m->name = $person->name;
			$this->person_m->surname = $person->surname;
			$this->person_m->user = $this->user_m;
			
			
			$this->load->library('person');
			$this->person->Insert($this->person_m);
			
			var_dump($this->person_m);
		}
		
		//Update person - /persons/person/$mail  [POST]
		if ($mail != "" && $_SERVER['REQUEST_METHOD'] == "POST")
		{
			echo "update";
		}
		
	}
	
	
	
}
?>